package org.wyn.mongodb.bean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Category;
import org.bson.types.ObjectId;
import org.wyn.common.Table;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * 关键字表
 * @author wyn
 *
 */
@Entity(value = Table.CollectionName.Keys, noClassnameStored = true)
public class Keys {

	@Id
	private ObjectId id;
	
	private String key;

	@Reference(ignoreMissing = true, value = "cate")
	private Category cate;
	
	/**
	 * 未处理数
	 */
	private int unhandleNum;
	
	/**
	 * 正确数
	 */
	private int effectiveNum;
	
	/**
	 * 错误数
	 */
	private int invainNum;
	
	private int total;

	/**
	 * 更新时间
	 */
	private long updateTime;
	
	/**
	 * 添加时间
	 */
	private long addTime;
	
	/**
	 * 查询得到结果总数
	 */
	private long searchedNum;
	
	/**
	 * 查准率
	 */
	private float hitRate;
	
	private int flag;

	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public long getSearchedNum() {
		return searchedNum;
	}
	public void setSearchedNum(long searchedNum) {
		this.searchedNum = searchedNum;
	}
	public float getHitRate() {
		return hitRate;
	}
	public void setHitRate(float hitRate) {
		this.hitRate = hitRate;
	}
	public Keys() {
		
	}
	public Keys(String keyword) {
		setKey(keyword);
		setEffectiveNum(0);
		setInvainNum(0);
		setUnhandleNum(0);
		setUpdateTime(System.currentTimeMillis());
		setAddTime(System.currentTimeMillis());
		//setFlag(KeyWordFlag.UNHANDLE_KEY);
	}

	public String getId() {
		return id.toString();
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public int getUnhandleNum() {
		return unhandleNum;
	}

	public void setUnhandleNum(int unhandleNum) {
		this.unhandleNum = unhandleNum;
	}

	public int getEffectiveNum() {
		return effectiveNum;
	}

	public void setEffectiveNum(int effectiveNum) {
		this.effectiveNum = effectiveNum;
	}

	public int getInvainNum() {
		return invainNum;
	}

	public void setInvainNum(int invainNum) {
		this.invainNum = invainNum;
	}

	public long getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(long updateTime) {
		this.updateTime = updateTime;
	}
	
	public DBObject toDBObject() {
		DBObject obj = new BasicDBObject();
		obj.put("key", key);
		obj.put("unhandleNum", unhandleNum);
		obj.put("effectiveNum", effectiveNum);
		obj.put("invainNum", invainNum);
		obj.put("updateTime", updateTime);
		obj.put("addTime", addTime);
		obj.put("searchedNum", searchedNum);
		obj.put("hitRate", hitRate);
		obj.put("flag", flag);
		obj.put("total", total);
		return obj;
	}
	
	public static void main(String[] args) throws ParseException {
		long b = System.currentTimeMillis();
		System.out.println(b);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date d = new Date(b);
		System.out.println(sdf.format(d));
	}
	public long getAddTime() {
		return addTime;
	}
	public void setAddTime(long addTime) {
		this.addTime = addTime;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public Category getCate() {
		return cate;
	}
	public void setCate(Category cate) {
		this.cate = cate;
	}
}
